import { messageDuration } from '/@/config'
import { ElMessage } from 'element-plus'

/**
 * @description 全局Message
 * @param {string|VNode} message 消息文字
 * @param {'success'|'warning'|'info'|'error'} type 主题
 * @param {string} customClass 自定义类名
 * @param {boolean} dangerouslyUseHTMLString 是否将message属性作为HTML片段处理
 */
export const baseMessage = (
  message: string | VNode,
  type: 'success' | 'warning' | 'info' | 'error' = 'success',
  customClass?: string,
  dangerouslyUseHTMLString?: boolean,
  callback?: any
) => {
  if (!customClass) customClass = `vab-hey-message-${type}`
  if (dangerouslyUseHTMLString && typeof dangerouslyUseHTMLString == 'function') {
    callback = dangerouslyUseHTMLString
    dangerouslyUseHTMLString = false
  }

  ElMessage({
    message,
    type,
    customClass,
    duration: messageDuration,
    dangerouslyUseHTMLString,
    showClose: false,
    onClose: () => {
      if (callback) callback()
    },
  })
}
